﻿#include "paragraph.h"
#include <QTextBlock>
#include <QInputDialog>
void myNotePad::headingActionSlot() {//多级标题
    QTextCursor cursor = mainText->textCursor();

    int lineNumber = cursor.blockNumber();
    cursor.movePosition(QTextCursor::StartOfLine);

    cursor.insertText("# ");

    mainText->setTextCursor(cursor);
}

void myNotePad::headingActionSlot(int n) {//多级标题
    QTextCursor cursor = mainText->textCursor();

    int lineNumber = cursor.blockNumber();
    cursor.movePosition(QTextCursor::StartOfLine);

    //int lineNumber = textEdit->textCursor().blockNumber(); // 获取当前行号
    //int columnNumber = textEdit->textCursor().columnNumber(); // 获取当前列号

    QString s = "#";

    while (--n)
    {
        s += "#";
    }
    s += " ";
    cursor.insertText(s);

    mainText->setTextCursor(cursor);
}

void myNotePad::increaseHeadingLevelActionSlot() {//提升标题级别

}

void myNotePad::decreaseHeadingLevelActionSlot() {//降低标题级别

}

void myNotePad::tableActionSlot() {//标题实现

}

void myNotePad::codeFencesActionSlot() {//代码块实现
    QString codeLanguage = "c++"; // 默认代码语言为C++
    QTextEdit* mainTextEdit = ui.centralWidget->findChild<QTextEdit*>("mainText", Qt::FindChildrenRecursively);
    QTextCursor cursor = mainTextEdit->textCursor();

    QString codeBlockText = "```\n\n```"; //标志字符串
    mainText->setTextCursor(this->getiTextCursor());
    iTextEdit::insertText(codeBlockText, this->getiTextCursor(), this->getViewMode());
}

void myNotePad::mathBlockActionSlot() {//公式快实现
    mainText->setTextCursor(this->getiTextCursor());

    // 插入数学公式块标记
    QString mathBlockText = "$$\n\n$$";
    iTextEdit::insertText(mathBlockText, this->getiTextCursor(), this->getViewMode());
    // 将光标移动到数学公式块内部，方便用户输入公式
    this->getiTextCursor().movePosition(QTextCursor::Up);
    this->getiTextCursor().movePosition(QTextCursor::EndOfBlock);
    mainText->setTextCursor(this->getiTextCursor());
}



void myNotePad::quoteActionSlot() {//引用实现
    // 获取当前文本编辑器的光标
    QTextCursor cursor = mainText->textCursor();
    QString qutoText = "> ";

    iTextEdit::insertText(qutoText, cursor, this->getViewMode());

    // 设置光标回到文本编辑器
    mainText->setTextCursor(cursor);
}






